﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace ServerASISTSYS
{
    /// <summary>
    /// Singleton class. Used to read server config file.
    /// </summary>
    class ServerConfig
    {
        // Constants
        static readonly int DEF_SERVER_PORT = 8080;        // default port

        private static ServerConfig _instance = null;      // ServerConfig instance

        public XMLParser xmlparser = null;

        // Private constructor
        private ServerConfig() { }

        /// <summary>
        /// Used to get the class instance
        /// </summary>
        /// <returns>The ServerConfig instance</returns>
        public static ServerConfig GetInstance()
        {
            if (_instance == null)
                _instance = new ServerConfig();

            return _instance;
        }

        public string GetAppPath()
        {
            string appPath = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().GetName().CodeBase);
            appPath = appPath.Substring(6); // cut "file:\\" from begining on path

            return appPath;
        }

        public string GetFilterPath()
        {
            return this.GetAppPath() + "\\Filters\\";
        }

        public int GetPort()
        {
            if (xmlparser == null)
            {
                if (System.IO.File.Exists(@".\Configurare.xml"))
                    xmlparser = new XMLParser(@"Configurare.xml");
                else
                    xmlparser = new XMLParser(@"C:\Configurare.xml");
            }

            return DEF_SERVER_PORT;
        }

    } /* class Constants */
} /* namespace ServerASISTSYS */
